using System;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;

namespace converter.template.item
{
    internal class TableRow : TemplateItem
    {
        public TableRow()
        {
        }

        // Is the row a part of the table's body?
        public bool IsBodyRow
        {
            get
            {
                return isBodyRow;
            }
            set
            {
                isBodyRow = value;
            }
        }

        public bool IsDetail
        {
            get
            {
                return isDetail;
            }
            set
            {
                isDetail = value;
            }
        }

        /// <summary>
        /// Creates the TableRow element.
        /// </summary>
        /// <param name="parent">The parent element -- Table.</param>
        public override void Build(OpenXmlCompositeElement parent)
        {
            DocumentFormat.OpenXml.Wordprocessing.TableRow elem = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
            parent.AppendChild(elem);

            // Build the cells.
            for (int i = 0; i < Items.Count; /*i++*/) // counter increments by the cell's columns span property.
            {
                TableCell cell = Items[i] as TableCell;
                cell.Build(elem);
                i += cell.GetColSpan();
            }
        }

        //public override void Build(Template template, net.windward.document.Document document, ElementTable table)
        //{
        //    ElementRow row = new ElementRow();
        //    table.addRow(row);

        //    // Build row cells.
        //    foreach (TemplateItem item in Items)
        //        item.Build(template, document, row);
        //}

        private bool isBodyRow = false;
        private bool isDetail = false;
    }
}
